$(".sg_tabs span").click(function(){
	$(".sg_tabs span").each(function(i){
		$(this).removeClass("tab_hover");
		$(this).addClass("tab");
	});
	$(this).addClass("tab_hover");
	$(this).removeClass("tab");
    c=$(this).attr("for");
    html=$("#"+c).html();
    $("#sg_cont").html(html);
    
});

$('#save').click(function(){

        $("#form1").submit();  

});


 $('a.popup').click(function(){
    var href=$(this).attr("href");
    popup(href);
 });

$(function(){
    $("#searchk").click(function(){
        ct=$("#city").val();
        cl=$("#class").val();
        key=$("#keyword").val();
        $.get("info/ajaxSearch", 
              { "keyword":key 
               ,"city":ct 
               ,"class":cl 
              },
              function(data){
                  $("#sr").html(data);
                  bindIco();
            }); 
        return false;
        
    });
  
});
function popup(href){
    $.fn.colorbox({
        inline:true 
        ,width:"400px"
        ,href:href
        ,open:true
    }); 
    return false;
}
function popPic(href){
    $.fn.colorbox({
        href:href
        ,open:true
    }); 
    return false;
}

$(".hd2").jCarouselLite({
            auto: 2000,
            visible: 4,
            speed: 2000
});

/*裁剪框相关js---start-----------*/
var baseUrl=$("#baseUrl").val()+"";

function ico(data){
    var json=eval('('+data+')'); 
    var rect={};
    rect.x=0;
    rect.y=0;
    rect.w=150;
    rect.h=150;

    cutPic(json["pics"][0],baseUrl+'photo/cutPic','ico_pic',rect,function(data){

            $("#ico").val(data);    
            $("#ico_tip").html("上传成功");
            $("#ico_tip").css("color","#459D00");

            });
}
function pic(data){
    var json=eval('('+data+')'); 
    var rect={};
    rect.x=50;
    rect.y=50;
    rect.w=200;
    rect.h=200;
    cutPic(json["pics"][0],baseUrl+'photo/cutPic','ad_pic',rect,function(data){

            $("#pic").val(data);    
            $("#pic_tip").html("上传成功");
            $("#pic_tip").css("color","#459D00");

            });
}
function slider(data){
    var json=eval('('+data+')'); 
    var rect={};
    rect.x=50;
    rect.y=50;
    rect.w=225;
    rect.h=150;
    cutPic(json["pics"][0],baseUrl+'photo/cutPic','slider_pic',rect,function(data){

            $("#slider").val(data);    
            $("#slider_tip").html("上传成功");
            $("#slider_tip").css("color","#459D00");

            });
}
function adsPic(data){
    var json=eval('('+data+')'); 
    var rect={};
    rect.x=0;
    rect.y=0;
    rect.w=200;
    rect.h=200;
    cutPic(json["pics"][0],baseUrl+'photo/cutPic','ico_pic',rect,function(data){

            $("#pic").val(data);    
            $("#pic_tip").html("上传成功");

            });
}

//图片地址，handleUrl地址,container的id，rect为裁剪框的矩形,callback函数
function cutPic(picUrl,handleUrl,container,rect,callback){
    //获取图片大小  
    $=jQuery;
    $("#"+container).html("");
    str ="<div id='"+container+"_cut_pic_box' class='cut_pic_box'>";
    str+="  <div id='"+container+"_cut_pic' class='cut_pic'>";
    str+="      <div class='cut_shadow'>";
    str+="      </div>";
    str+="      <div title='双击裁剪' id='"+container+"_cut_ico' class='cut_ico'>";
    str+="      </div>";
    str+="  </div>";
    str+="</div>";
    str+="<img id='"+container+"_cut_image' style='display:none' src='"+picUrl+"' />";
    $("#"+container).append(str);

    var x=rect.x;
    var y=rect.y;
    var w=rect.w;
    var h=rect.h;

    $("#"+container+"_cut_image").load(function(){


            width=$(this).width();
            height=$(this).height();
            $("#"+container+"_cut_pic").height(height);
            $("#"+container+"_cut_pic").width(width);
            $("#"+container+"_cut_pic").css("background","url("+picUrl+")");
            $("#"+container+"_cut_ico").css("background","url("+picUrl+")");
            $("#"+container+"_cut_ico").css("width",w);
            $("#"+container+"_cut_ico").css("height",h);
            $("#"+container+"_cut_ico").css("top",y);
            $("#"+container+"_cut_ico").css("left",x);
            var v=-x+"px "+(-y+"px");
            $('#'+container+'_cut_ico').css('background-position',v);
            $("#"+container+"_cut_ico").mousedown(function(e){
                var startX=e.clientX;
                var startY=e.clientY;
                var orginX=this.offsetLeft;
                var orginY=this.offsetTop;
                var deltaX=startX-orginX;
                var deltaY=startY-orginY;

                $('#'+container+'_cut_ico').mousemove(drag);

                $('#'+container+'_cut_ico').mouseup(function(e){
                    $('#'+container+'_cut_ico').unbind('mousemove',drag); 
                    })
                $('#'+container+'_cut_ico').mouseout(function(e){
                    $('#'+container+'_cut_ico').unbind('mousemove',drag); 
                    });       

                //拖动函数绑定mousemove事件
                function drag(e){
                x=e.clientX-deltaX;
                y=e.clientY-deltaY;
                //console.log("(x:"+x+",y:"+y+")");
                w=$('#'+container+'_cut_ico').width(); 
                h=$('#'+container+'_cut_ico').height();
                bw=$('#'+container+'_cut_pic').width();
                bh=$('#'+container+'_cut_pic').height();
                //边界控制
                if(x+w>bw){
                    x=bw-w-2;
                }
                if(y+h>bh){
                    y=bh-h-2;
                }
                if(y<0){
                    y=2;
                }
                if(x<0){
                    x=2
                }
                var v=-x+"px "+(-y+"px");
                $('#'+container+'_cut_ico').css('background-position',v);
                $('#'+container+'_cut_ico').css({top:y,left:x});

                }
                return false;

            });
            $("#"+container+"_cut_ico").dblclick(function(e){
                    $.get(handleUrl, { "x":x,"y":y,"w":w,"h":h,"url":picUrl},
                        function(data){
                        var img="<img src='"+data+"?"+(new Date().getTime())+"' />";
                        $("#"+container).html(img);
                        callback(data)

                        }); 

                    });

    });  

}
/*裁剪框相关js---end-----------*/

function bindIco(){
$(document).ready(function() {
 
    //move the image in pixel
    var move = -15;
     
    //zoom percentage, 1.2 =120%
    var zoom = 1.2;
 
    //On mouse over those thumbnail
    $('.item').hover(function() {
         
        //Set the width and height according to the zoom percentage
        width = $('.item').width() * zoom;
        height = $('.item').height() * zoom;
         
        //Move and zoom the image
        $(this).find('img').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:200});
         
        //Display the caption
        $(this).find('div.caption').stop(false,true).fadeIn(200);
    },
    function() {
        //Reset the image
        $(this).find('img').stop(false,true).animate({'width':$('.item').width(), 'height':$('.item').height(), 'top':'0', 'left':'0'}, {duration:100});    
 
        //Hide the caption
        $(this).find('div.caption').stop(false,true).fadeOut(200);
    });
});
}
/*******修改*******************/

bindIco();

    $(".s_tab_1").mouseover(function(){
            $(this).css("background-image","url(public/images/btn-l-h.png)")
            });
    $(".s_tab_1").mouseout(function(){
            $(this).css("background-image","url(public/images/btn-l.png)")
            });
    $(".s_tab_2").mouseover(function(){
            $(this).css("background-image","url(public/images/btn-r-h.png)")
            });
    $(".s_tab_2").mouseout(function(){
            $(this).css("background-image","url(public/images/btn-r.png)")
            });
    $(".s_tab_1").click(function(){
            $(".tab1").css("display","block");
            $(".tab2").css("display","none");
            return false;
            });
    $(".s_tab_2").click(function(){
            $(".tab2").css("display","block");
            $(".tab1").css("display","none");
            return false;
            });
